//
//  TSBaseNavigationController.m
//  tryshopping.boss
//
//  Created by Mr.Lee on 16/11/8.
//  Copyright © 2016年 Reabam. All rights reserved.
//

#import "TSBaseNavigationController.h"

@interface TSBaseNavigationController () <UIGestureRecognizerDelegate>
@end

@implementation TSBaseNavigationController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    // 增加滑动返回手势
//    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
//    pan.delegate = self;
//    [self.view addGestureRecognizer:pan];
//    self.interactivePopGestureRecognizer.enabled = NO;
//
}
#pragma mark - UIGestureRecognizerDelegate
//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
//{
//    return self.childViewControllers.count != 1;
//}


+ (void)load {
    // 获取全局导航条
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    // 设置导航条标题字体的颜色和大小
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont systemFontOfSize:19];
    attr[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [navBar setTitleTextAttributes:attr];
    
    // 设置导航条背景图片
    //[navBar setBackgroundImage:[UIImage imageNamed:@"baisebeijingtupian"] forBarMetrics:UIBarMetricsDefault];
    // 设置导航条白色
//    UIImage *colorImage = [self imageWithColor:[UIColor whiteColor] size:CGSizeMake(ScreenWidth, 64)];
    UIImage *colorImage = [self imageWithColor:lanse size:CGSizeMake(ScreenWidth, 64)];
    [navBar setBackgroundImage:colorImage forBarMetrics:UIBarMetricsDefault];
    // 设置导航条的分割线
//    [navBar setShadowImage:[self imageWithColor:[UIColor colorWithHexString:@"e6e6e6"] size:CGSizeMake(ScreenWidth, 0.5)]];
    [navBar setShadowImage:[self imageWithColor:lanse size:CGSizeMake(ScreenWidth, 0.5)]];
}

// 根据颜色设置图片
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
    
    if (!color || size.width <=0 || size.height <=0) return nil;
    
    CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
    
    UIGraphicsBeginImageContextWithOptions(rect.size,NO, 0);
    
    CGContextRef context =UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, color.CGColor);
    
    CGContextFillRect(context, rect);
    
    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
    
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // 不是根控制器才需要设置
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIImage *img=[UIImage imageNamed:@"fanhui"];
        UIImage *tinted = [img rt_tintedImageWithColor:[UIColor whiteColor]];
//        [_switchBtn setImage:tinted forState:UIControlStateNormal];
//        [_switchBtn setImage:tinted forState:UIControlStateHighlighted];
        
        
        UIBarButtonItem *backItem = [UIBarButtonItem backItemWithImage:tinted highImage:tinted target:self action:@selector(back) norColor:[UIColor clearColor] highColor:[UIColor clearColor] title:nil];
//        UIBarButtonItem *backItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"fanhui"] highImage:[UIImage imageNamed:@"fanhui"] target:self action:@selector(back)];
        viewController.navigationItem.leftBarButtonItem = backItem;
    
    }
    [super pushViewController:viewController animated:animated];
}

// 点击返回按钮,回到上一个界面
- (void)back {
    [self popViewControllerAnimated:YES];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
//- (void)viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:animated];
//}

@end
